#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>

int My_atoi(const char* str)
{
	int ret = 0;
	int flag = 0;
	const char* start = str;
	while (*start)
	{
		while (*start >= '0'&&*start <= '9')
		{
			flag = 1;
			ret = ret * 10 + (*start - '0');
			start++;
		}
		if (flag)
		{
			break;
		}
		start++;
	}
	return ret;
}

int main()
{
	char buffer1[20] = "";
	char buffer2[20] = "   ";
	char buffer3[20] = "   0123";
	char buffer4[20] = "   0123   ****45";
	char buffer5[20] = "0123";
	char buffer6[20] = "0123    *****456";
	char buffer7[20] = "000000000";
	char buffer8[20] = "0     0123";
	char buffer9[20] = "0       *&*";
	char buffer10[20] = "$$$$$$   123";
	char buffer11[20] = "%%%%%% 0 123";

	printf("The value entered is %d\n", My_atoi(buffer1));
	printf("The value entered is %d\n", My_atoi(buffer2));
	printf("The value entered is %d\n", My_atoi(buffer3));
	printf("The value entered is %d\n", My_atoi(buffer4));
	printf("The value entered is %d\n", My_atoi(buffer5));
	printf("The value entered is %d\n", My_atoi(buffer6));
	printf("The value entered is %d\n", My_atoi(buffer7));
	printf("The value entered is %d\n", My_atoi(buffer8));
	printf("The value entered is %d\n", My_atoi(buffer9));
	printf("The value entered is %d\n", My_atoi(buffer10));
	printf("The value entered is %d\n", My_atoi(buffer11));

	return 0;
}